layui.extend({
    admin: '{/}../../static/js/admin'
});
layui.use(['laydate', 'jquery', 'admin'], function () {
    var laydate = layui.laydate,
        $ = layui.jquery,
        admin = layui.admin;
    //执行一个laydate实例
    laydate.render({
        elem: '#start' //指定元素
    });
    //执行一个laydate实例
    laydate.render({
        elem: '#end' //指定元素
    });
    /*用户-停用*/
    window.member_stop = function (obj, id) {
        var id = $(obj).parent(".td-manage").parent("tr").attr("data-id")
        if ($(obj).attr('title') == '启用') {
            layer.confirm('确认要停用吗？', function (index) {
                $.get({url: "/product/stop/"+id,async: false})
                $(obj).attr('title', '停用')
                $(obj).find('i').removeClass('layui-icon-download-circle').addClass('layui-icon-upload-circle');
                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!', {
                    icon: 5,
                    time: 1000
                });
            })
        } else {
            layer.confirm('确认要启用吗？', function (index) {
                $.get({url: "/product/invocation/"+id,async: false})
                $(obj).attr('title', '启用')
                $(obj).find('i').removeClass('layui-icon-upload-circle').addClass('layui-icon-download-circle');
                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!', {
                    icon: 6,
                    time: 1000
                });
            })
        }
    }

    /*用户-删除*/
    window.member_del = function (obj) {
        layer.confirm('确认要删除吗？', function () {
            var id = $(obj).parent(".td-manage").parent("tr").attr("data-id")
            var nowPage = $(".list").children().length
            //发异步删除数据
            $.get({
                url: "/product/del/"+id,
                success: function(data) {
                    $("#productList").html(data)
                },
                async: false
            })
            var num = parseInt($(".fr>span").html())
            $(".fr>span").html(--num);
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {
                icon: 1,
                time: 1000
            });
        });
    }
});